namespace SourceFoundry.Utilities.BugManagement
{
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Configuration;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Net;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Security.Principal;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Threading;
    using System.Windows.Forms;

    public class CrashManager2
    {
        static CrashManager2()
        {
            CrashManager._ScreenshotImageFormat = ImageFormat.Png;
            CrashManager._objParentAssembly = null;
        }

        private CrashManager2()
        {
        }

        public static void AddHandler([Optional] bool blnConsoleApp /* = false */)
        {
            CrashManager.LoadConfigSettings();
            if (!CrashManager._blnIgnoreDebugErrors || !Debugger.IsAttached)
            {
                CrashManager.ParentAssembly();
                Application.ThreadException -= new ThreadExceptionEventHandler(CrashManager.ThreadExceptionHandler);
                Application.ThreadException += new ThreadExceptionEventHandler(CrashManager.ThreadExceptionHandler);
                AppDomain.CurrentDomain.UnhandledException -= new UnhandledExceptionEventHandler(CrashManager.UnhandledExceptionHandler);
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CrashManager.UnhandledExceptionHandler);
                CrashManager._blnConsoleApp = blnConsoleApp;
            }
        }

        public static DateTime AssemblyBuildDate(Assembly objAssembly, [Optional] bool blnForceFileDate /* = false */)
        {
            Version version1 = objAssembly.GetName().Version;
            if (blnForceFileDate)
            {
                return CrashManager.AssemblyFileTime(objAssembly);
            }
            DateTime time3 = Conversions.ToDate("01/01/2000");
            DateTime time4 = time3.AddDays((double) version1.Build);
            DateTime time2 = time4.AddSeconds((double) (version1.Revision * 2));
            if (TimeZone.IsDaylightSavingTime(DateTime.Now, TimeZone.CurrentTimeZone.GetDaylightChanges(DateTime.Now.Year)))
            {
                time2 = time2.AddHours(1);
            }
            if (((DateTime.Compare(time2, DateTime.Now) > 0) | (version1.Build < 730)) | (version1.Revision == 0))
            {
                time2 = CrashManager.AssemblyFileTime(objAssembly);
            }
            return time2;
        }

        private static DateTime AssemblyFileTime(Assembly objAssembly)
        {
            DateTime time1;
            try
            {
                time1 = File.GetLastWriteTime(objAssembly.Location);
            }
            catch (Exception exception2)
            {
                ProjectData.SetProjectError(exception2);
                Exception exception1 = exception2;
                time1 = DateTime.MaxValue;
                ProjectData.ClearProjectError();
                return time1;
                //ProjectData.ClearProjectError();
            }
            return time1;
        }

        [DllImport("gdi32", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        private static extern int BitBlt(int hDestDC, int x, int y, int nWidth, int nHeight, int hSrcDC, int xSrc, int ySrc, int dwRop);
        private static void BitmapToJPEG(Bitmap objBitmap, string strFilename, [Optional] long lngCompression /* = 0x4b */)
        {
            EncoderParameters parameters1 = new EncoderParameters(1);
            ImageCodecInfo info1 = CrashManager.GetEncoderInfo("image/jpeg");
            parameters1.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, lngCompression);
            objBitmap.Save(strFilename, info1, parameters1);
        }

        //private static string CurrentEnvironmentIdentity()
        //{
        //    string text1;
        //    try
        //    {
        //        text1 = Environment.UserDomainName + @"\" + Environment.UserName;
        //    }
        //    catch (Exception exception2)
        //    {
        //        ProjectData.SetProjectError(exception2);
        //        Exception exception1 = exception2;
        //        text1 = "";
        //        ProjectData.ClearProjectError();
        //        return text1;
        //        //ProjectData.ClearProjectError();
        //    }
        //    return text1;
        //}

        //private static string CurrentWindowsIdentity()
        //{
        //    string text1;
        //    try
        //    {
        //        text1 = WindowsIdentity.GetCurrent().Name;
        //    }
        //    catch (Exception exception2)
        //    {
        //        ProjectData.SetProjectError(exception2);
        //        Exception exception1 = exception2;
        //        text1 = "";
        //        ProjectData.ClearProjectError();
        //        return text1;
        //        //ProjectData.ClearProjectError();
        //    }
        //    return text1;
        //}

        //public static string EnhancedStackTrace()
        //{
        //    StackTrace trace1 = new StackTrace(true);
        //    return CrashManager.EnhancedStackTrace(trace1, "ExceptionManager");
        //}

        //public static string EnhancedStackTrace(Exception objException)
        //{
        //    StackTrace trace1 = new StackTrace(objException, true);
        //    return CrashManager.EnhancedStackTrace(trace1, "");
        //}

        //public static string EnhancedStackTrace(StackTrace objStackTrace, [Optional] string strSkipClassName /* = "" */)
        //{
        //    StringBuilder builder1 = new StringBuilder();
        //    builder1.Append(Environment.NewLine);
        //    builder1.Append("---- Stack Trace ----");
        //    builder1.Append(Environment.NewLine);
        //    int num2 = objStackTrace.FrameCount - 1;
        //    for (int num1 = 0; num1 <= num2; num1++)
        //    {
        //        StackFrame frame1 = objStackTrace.GetFrame(num1);
        //        MemberInfo info1 = frame1.GetMethod();
        //        if ((((Operators.CompareString(strSkipClassName, "", false) != 0) && (info1.DeclaringType.Name.IndexOf(strSkipClassName) > -1)) ? 1 : 0) == 0)
        //        {
        //            builder1.Append(CrashManager.StackFrameToString(frame1));
        //        }
        //    }
        //    builder1.Append(Environment.NewLine);
        //    return builder1.ToString();
        //}

        private static void ExceptionToConsole()
        {
            Console.WriteLine("This application encountered an unexpected problem.");
            Console.WriteLine(CrashManager.FormatExceptionForUser(true));
            Console.WriteLine("The application must now terminate. Press ENTER to continue...");
            Console.ReadLine();
        }

        private static void ExceptionToEmail()
        {
            Thread thread1 = new Thread(new ThreadStart(CrashManager.ThreadHandler));
            thread1.Name = "SendExceptionEmail";
            thread1.Start();
        }

        private static void ExceptionToEventLog()
        {
            try
            {
                EventLog.WriteEntry(AppDomain.CurrentDomain.FriendlyName, Environment.NewLine + CrashManager._strException, EventLogEntryType.Error);
                CrashManager._blnLogToEventLogOK = true;
            }
            catch (Exception exception2)
            {
                ProjectData.SetProjectError(exception2);
                Exception exception1 = exception2;
                CrashManager._blnLogToEventLogOK = false;
                ProjectData.ClearProjectError();
            }
        }

        //private static void ExceptionToFile()
        //{
        //    CrashManager._strLogFullPath = CrashManager.GetApplicationPath() + "UnhandledExceptionLog.txt";
        //    try
        //    {
        //        StreamWriter writer1 = new StreamWriter(CrashManager._strLogFullPath, true);
        //        writer1.Write(CrashManager._strException);
        //        writer1.WriteLine();
        //        writer1.Close();
        //        CrashManager._blnLogToFileOK = true;
        //    }
        //    catch (Exception exception2)
        //    {
        //        ProjectData.SetProjectError(exception2);
        //        Exception exception1 = exception2;
        //        CrashManager._blnLogToFileOK = false;
        //        ProjectData.ClearProjectError();
        //    }
        //}

        //private static void ExceptionToScreenshot()
        //{
        //    try
        //    {
        //        //CrashManager.TakeScreenshotPrivate(CrashManager.GetApplicationPath() + "UnhandledException");
        //        CrashManager._blnLogToScreenshotOK = true;
        //    }
        //    catch (Exception exception2)
        //    {
        //        ProjectData.SetProjectError(exception2);
        //        Exception exception1 = exception2;
        //        CrashManager._blnLogToScreenshotOK = false;
        //        ProjectData.ClearProjectError();
        //    }
        //}

        internal static string ExceptionToString(Exception objException)
        {
            StringBuilder builder1 = new StringBuilder();
            if (objException.InnerException != null)
            {
                StringBuilder builder2 = builder1;
                builder2.Append("(Inner Exception)");
                builder2.Append(Environment.NewLine);
                builder2.Append(CrashManager.ExceptionToString(objException.InnerException));
                builder2.Append(Environment.NewLine);
                builder2.Append("(Outer Exception)");
                builder2.Append(Environment.NewLine);
                builder2 = null;
            }
            StringBuilder builder3 = builder1;
            builder3.Append(CrashManager.SysInfoToString(false));
            builder3.Append("Exception Source:      ");
            try
            {
                builder3.Append(objException.Source);
            }
            catch (Exception exception6)
            {
                ProjectData.SetProjectError(exception6);
                Exception exception1 = exception6;
                builder3.Append(exception1.Message);
                ProjectData.ClearProjectError();
            }
            builder3.Append(Environment.NewLine);
            builder3.Append("Exception Type:        ");
            try
            {
                builder3.Append(objException.GetType().FullName);
            }
            catch (Exception exception7)
            {
                ProjectData.SetProjectError(exception7);
                Exception exception2 = exception7;
                builder3.Append(exception2.Message);
                ProjectData.ClearProjectError();
            }
            builder3.Append(Environment.NewLine);
            builder3.Append("Exception Message:     ");
            try
            {
                builder3.Append(objException.Message);
            }
            catch (Exception exception8)
            {
                ProjectData.SetProjectError(exception8);
                Exception exception3 = exception8;
                builder3.Append(exception3.Message);
                ProjectData.ClearProjectError();
            }
            builder3.Append(Environment.NewLine);
            builder3.Append("Exception Target Site: ");
            try
            {
                builder3.Append(objException.TargetSite.Name);
            }
            catch (Exception exception9)
            {
                ProjectData.SetProjectError(exception9);
                Exception exception4 = exception9;
                builder3.Append(exception4.Message);
                ProjectData.ClearProjectError();
            }
            builder3.Append(Environment.NewLine);
            try
            {
                //string text2 = CrashManager.EnhancedStackTrace(objException);
                //builder3.Append(text2);
            }
            catch (Exception exception10)
            {
                ProjectData.SetProjectError(exception10);
                Exception exception5 = exception10;
                builder3.Append(exception5.Message);
                ProjectData.ClearProjectError();
            }
            builder3.Append(Environment.NewLine);
            builder3 = null;
            return builder1.ToString();
        }

        private static void ExceptionToUI()
        {
            string text1;
            //if (CrashManager.KillAppOnException)
            //{
            //    text1 = "When you click OK, (app) will close.";
            //}
            //else
            //{
            //    text1 = "The action you requested was not performed.";
            //}
            //if (!CrashManager._blnConsoleApp)
            //{
            //    HandledCrashManager.EmailError = !CrashManager.SendEmail;
                HandledCrashManager.ShowDialog("There was an unexpected error in (app). This may be due to a programming bug.", "text1", "Restart (app), and try repeating your last action. Try alternative methods of performing the same action.", CrashManager.FormatExceptionForUser(false), MessageBoxButtons.OK, MessageBoxIcon.Hand, HandledCrashManager.UserErrorDefaultButton.Default);
            //}
            //else
            //{
            //    CrashManager.ExceptionToConsole();
            //}
        }

        private static string FormatExceptionForUser(bool blnConsoleApp)
        {
            string text2;
            StringBuilder builder1 = new StringBuilder();
            if (blnConsoleApp)
            {
                text2 = "-";
            }
            else
            {
                text2 = "\u2022";
            }
            StringBuilder builder2 = builder1;
            if (!blnConsoleApp)
            {
                builder2.Append("The development team was automatically notified of this problem. ");
                builder2.Append("If you need immediate assistance, contact (contact).");
            }
            builder2.Append(Environment.NewLine);
            builder2.Append(Environment.NewLine);
            builder2.Append("The following information about the error was automatically captured: ");
            builder2.Append(Environment.NewLine);
            builder2.Append(Environment.NewLine);
            if (CrashManager._blnLogToScreenshot)
            {
                builder2.Append(" ");
                builder2.Append(text2);
                builder2.Append(" ");
                if (CrashManager._blnLogToScreenshotOK)
                {
                    builder2.Append("a screenshot was taken of the desktop at:");
                    builder2.Append(Environment.NewLine);
                    builder2.Append("   ");
                    builder2.Append(CrashManager._strScreenshotFullPath);
                }
                else
                {
                    builder2.Append("a screenshot could NOT be taken of the desktop.");
                }
                builder2.Append(Environment.NewLine);
            }
            if (CrashManager._blnLogToEventLog)
            {
                builder2.Append(" ");
                builder2.Append(text2);
                builder2.Append(" ");
                if (CrashManager._blnLogToEventLogOK)
                {
                    builder2.Append("an event was written to the application log");
                }
                else
                {
                    builder2.Append("an event could NOT be written to the application log");
                }
                builder2.Append(Environment.NewLine);
            }
            if (CrashManager._blnLogToFile)
            {
                builder2.Append(" ");
                builder2.Append(text2);
                builder2.Append(" ");
                if (CrashManager._blnLogToFileOK)
                {
                    builder2.Append("details were written to a text log at:");
                }
                else
                {
                    builder2.Append("details could NOT be written to the text log at:");
                }
                builder2.Append(Environment.NewLine);
                builder2.Append("   ");
                builder2.Append(CrashManager._strLogFullPath);
                builder2.Append(Environment.NewLine);
            }
            if (CrashManager._blnLogToEmail)
            {
                builder2.Append(" ");
                builder2.Append(text2);
                builder2.Append(" ");
                builder2.Append("attempted to send an email to: ");
                builder2.Append(Environment.NewLine);
                builder2.Append("   ");
                builder2.Append(CrashManager.GetConfigString("EmailTo", null));
                builder2.Append(Environment.NewLine);
            }
            builder2.Append(Environment.NewLine);
            builder2.Append(Environment.NewLine);
            builder2.Append("Detailed error information follows:");
            builder2.Append(Environment.NewLine);
            builder2.Append(Environment.NewLine);
            builder2.Append(CrashManager._strException);
            builder2 = null;
            return builder1.ToString();
        }

        private static void GenericExceptionHandler(Exception objException)
        {
            try
            {
                CrashManager._strException = CrashManager.ExceptionToString(objException);
                CrashManager._strExceptionType = objException.GetType().FullName;
            }
            catch (Exception exception3)
            {
                ProjectData.SetProjectError(exception3);
                Exception exception1 = exception3;
                CrashManager._strException = "Error '" + exception1.Message + "' while generating exception string";
                CrashManager._strExceptionType = "";
                ProjectData.ClearProjectError();
            }
            if (!CrashManager._blnConsoleApp)
            {
                Cursor.Current = Cursors.WaitCursor;
            }
            try
            {
                if (CrashManager._blnLogToScreenshot)
                {
                    //CrashManager.ExceptionToScreenshot();
                }
                if (CrashManager._blnLogToEventLog)
                {
                    CrashManager.ExceptionToEventLog();
                }
                if (CrashManager._blnLogToFile)
                {
                    //CrashManager.ExceptionToFile();
                }
                if (CrashManager._blnLogToEmail)
                {
                    CrashManager.ExceptionToEmail();
                }
            }
            catch (Exception exception4)
            {
                ProjectData.SetProjectError(exception4);
                Exception exception2 = exception4;
                ProjectData.ClearProjectError();
            }
            if (!CrashManager._blnConsoleApp)
            {
                Cursor.Current = Cursors.Default;
            }
            if (CrashManager._blnLogToUI)
            {
                CrashManager.ExceptionToUI();
            }
            if (CrashManager._blnKillAppOnException)
            {
                CrashManager.KillApp();
                Application.Exit();
            }
        }

        private static string GetApplicationPath()
        {
            if (CrashManager.ParentAssembly().CodeBase.StartsWith("http://"))
            {
                return (@"c:\" + Regex.Replace(CrashManager.ParentAssembly().CodeBase, "[\\/\\\\\\:\\*\\?\\\"\\<\\>\\|]", "_") + ".");
            }
            return (AppDomain.CurrentDomain.BaseDirectory + AppDomain.CurrentDomain.FriendlyName + ".");
        }

        private static bool GetConfigBoolean(string strKey, [Optional] bool blnDefault /* = false */)
        {
            string text1;
            try
            {
                text1 = ConfigurationSettings.AppSettings.Get("CrashManager/" + strKey);
            }
            catch (Exception exception2)
            {
                bool flag1;
                ProjectData.SetProjectError(exception2);
                Exception exception1 = exception2;
                if (!blnDefault)
                {
                    flag1 = false;
                    ProjectData.ClearProjectError();
                    return flag1;
                }
                flag1 = blnDefault;
                ProjectData.ClearProjectError();
                return flag1;
                //ProjectData.ClearProjectError();
            }
            if (Operators.CompareString(text1, null, false) == 0)
            {
                if (!blnDefault)
                {
                    return false;
                }
                return blnDefault;
            }
            string text2 = text1.ToLower();
            if ((((Operators.CompareString(text2, "1", false) == 0) || (Operators.CompareString(text2, "true", false) == 0)) ? 1 : 0) != 0)
            {
                return true;
            }
            return false;
        }

        private static string GetConfigString(string strKey, [Optional] string strDefault /* = null */)
        {
            string text1;
            try
            {
                string text2 = ConfigurationSettings.AppSettings.Get("CrashManager/" + strKey);
                if (Operators.CompareString(text2, null, false) == 0)
                {
                    if (strDefault == null)
                    {
                        return string.Format("The key <{0}> is not present in the <appSettings> section of .config file", "CrashManager/" + strKey);
                    }
                    return strDefault;
                }
                text1 = text2;
            }
            catch (Exception exception2)
            {
                ProjectData.SetProjectError(exception2);
                Exception exception1 = exception2;
                if (strDefault == null)
                {
                    text1 = string.Format("Error {0} retrieving key <{1}> from <appSettings> section of .config file", exception1.Message, "CrashManager/" + strKey);
                    ProjectData.ClearProjectError();
                    return text1;
                }
                text1 = strDefault;
                ProjectData.ClearProjectError();
                return text1;
                //ProjectData.ClearProjectError();
            }
            return text1;
        }

        private static string GetCurrentIP()
        {
            string text1;
            try
            {
                string text2 = Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString();
                text1 = text2;
            }
            catch (Exception exception2)
            {
                ProjectData.SetProjectError(exception2);
                Exception exception1 = exception2;
                text1 = "127.0.0.1";
                ProjectData.ClearProjectError();
                return text1;
                //ProjectData.ClearProjectError();
            }
            return text1;
        }

        [DllImport("user32", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        private static extern int GetDC(int hwnd);
        private static ImageCodecInfo GetEncoderInfo(string strMimeType)
        {
            ImageCodecInfo[] infoArray1 = ImageCodecInfo.GetImageEncoders();
            for (int num1 = 0; num1 < infoArray1.Length; num1++)
            {
                if (Operators.CompareString(infoArray1[num1].MimeType, strMimeType, false) == 0)
                {
                    return infoArray1[num1];
                }
            }
            return null;
        }

        private static void KillApp()
        {
            Process.GetCurrentProcess().Kill();
        }

        private static void LoadConfigSettings()
        {
            //CrashManager.SendEmail = CrashManager.GetConfigBoolean("SendEmail", true);
            //CrashManager.TakeScreenshot = CrashManager.GetConfigBoolean("TakeScreenshot", true);
            //CrashManager.EmailScreenshot = CrashManager.GetConfigBoolean("EmailScreenshot", true);
            //CrashManager.LogToEventLog = CrashManager.GetConfigBoolean("LogToEventLog", false);
            //CrashManager.LogToFile = CrashManager.GetConfigBoolean("LogToFile", true);
            //CrashManager.DisplayDialog = CrashManager.GetConfigBoolean("DisplayDialog", true);
            //CrashManager.IgnoreDebugErrors = CrashManager.GetConfigBoolean("IgnoreDebug", true);
            //CrashManager.KillAppOnException = CrashManager.GetConfigBoolean("KillAppOnException", true);
        }

        public static Assembly ParentAssembly()
        {
            if (CrashManager._objParentAssembly == null)
            {
                if (Assembly.GetEntryAssembly() == null)
                {
                    CrashManager._objParentAssembly = Assembly.GetCallingAssembly();
                }
                else
                {
                    CrashManager._objParentAssembly = Assembly.GetEntryAssembly();
                }
            }
            return CrashManager._objParentAssembly;
        }

        [DllImport("user32", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        private static extern int ReleaseDC(int hwnd, int hdc);
        private static string StackFrameToString(StackFrame sf)
        {
            StringBuilder builder1 = new StringBuilder();
            MemberInfo info1 = sf.GetMethod();
            StringBuilder builder2 = builder1;
            builder2.Append("   ");
            builder2.Append(info1.DeclaringType.Namespace);
            builder2.Append(".");
            builder2.Append(info1.DeclaringType.Name);
            builder2.Append(".");
            builder2.Append(info1.Name);
            ParameterInfo[] infoArray1 = sf.GetMethod().GetParameters();
            builder2.Append("(");
            int num1 = 0;
            ParameterInfo[] infoArray2 = infoArray1;
            for (int num2 = 0; num2 < infoArray2.Length; num2++)
            {
                ParameterInfo info2 = infoArray2[num2];
                num1++;
                if (num1 > 1)
                {
                    builder2.Append(", ");
                }
                builder2.Append(info2.Name);
                builder2.Append(" As ");
                builder2.Append(info2.ParameterType.Name);
            }
            builder2.Append(")");
            builder2.Append(Environment.NewLine);
            builder2.Append("       ");
            if ((((sf.GetFileName() == null) || (sf.GetFileName().Length == 0)) ? 1 : 0) != 0)
            {
                builder2.Append(Path.GetFileName(CrashManager.ParentAssembly().CodeBase));
                builder2.Append(": N ");
                builder2.Append(string.Format("{0:#00000}", sf.GetNativeOffset()));
            }
            else
            {
                builder2.Append(Path.GetFileName(sf.GetFileName()));
                builder2.Append(": line ");
                builder2.Append(string.Format("{0:#0000}", sf.GetFileLineNumber()));
                builder2.Append(", col ");
                builder2.Append(string.Format("{0:#00}", sf.GetFileColumnNumber()));
                if (sf.GetILOffset() != -1)
                {
                    builder2.Append(", IL ");
                    builder2.Append(string.Format("{0:#0000}", sf.GetILOffset()));
                }
            }
            builder2.Append(Environment.NewLine);
            builder2 = null;
            return builder1.ToString();
        }

        internal static string SysInfoToString(bool blnIncludeStackTrace)
        {
            StringBuilder builder1 = new StringBuilder();
            StringBuilder builder2 = builder1;
            builder2.Append("Date and Time:         ");
            builder2.Append(DateTime.Now);
            builder2.Append(Environment.NewLine);
            builder2.Append("Machine Name:          ");
            try
            {
                builder2.Append(Environment.MachineName);
            }
            catch (Exception exception7)
            {
                ProjectData.SetProjectError(exception7);
                Exception exception1 = exception7;
                builder2.Append(exception1.Message);
                ProjectData.ClearProjectError();
            }
            builder2.Append(Environment.NewLine);
            builder2.Append("IP Address:            ");
            builder2.Append(CrashManager.GetCurrentIP());
            builder2.Append(Environment.NewLine);
            builder2.Append("Current User:          ");
            //builder2.Append(CrashManager.UserIdentity());
            builder2.Append(Environment.NewLine);
            builder2.Append(Environment.NewLine);
            builder2.Append("Application Domain:    ");
            try
            {
                builder2.Append(AppDomain.CurrentDomain.FriendlyName);
            }
            catch (Exception exception8)
            {
                ProjectData.SetProjectError(exception8);
                Exception exception2 = exception8;
                builder2.Append(exception2.Message);
                ProjectData.ClearProjectError();
            }
            builder2.Append(Environment.NewLine);
            builder2.Append("Assembly Codebase:     ");
            try
            {
                builder2.Append(CrashManager.ParentAssembly().CodeBase);
            }
            catch (Exception exception9)
            {
                ProjectData.SetProjectError(exception9);
                Exception exception3 = exception9;
                builder2.Append(exception3.Message);
                ProjectData.ClearProjectError();
            }
            builder2.Append(Environment.NewLine);
            builder2.Append("Assembly Full Name:    ");
            try
            {
                builder2.Append(CrashManager.ParentAssembly().FullName);
            }
            catch (Exception exception10)
            {
                ProjectData.SetProjectError(exception10);
                Exception exception4 = exception10;
                builder2.Append(exception4.Message);
                ProjectData.ClearProjectError();
            }
            builder2.Append(Environment.NewLine);
            builder2.Append("Assembly Version:      ");
            try
            {
                builder2.Append(CrashManager.ParentAssembly().GetName().Version.ToString());
            }
            catch (Exception exception11)
            {
                ProjectData.SetProjectError(exception11);
                Exception exception5 = exception11;
                builder2.Append(exception5.Message);
                ProjectData.ClearProjectError();
            }
            builder2.Append(Environment.NewLine);
            builder2.Append("Assembly Build Date:   ");
            try
            {
                DateTime time1 = CrashManager.AssemblyBuildDate(CrashManager.ParentAssembly(), false);
                builder2.Append(time1.ToString());
            }
            catch (Exception exception12)
            {
                ProjectData.SetProjectError(exception12);
                Exception exception6 = exception12;
                builder2.Append(exception6.Message);
                ProjectData.ClearProjectError();
            }
            builder2.Append(Environment.NewLine);
            builder2.Append(Environment.NewLine);
            if (blnIncludeStackTrace)
            {
                //builder2.Append(CrashManager.EnhancedStackTrace());
            }
            builder2 = null;
            return builder1.ToString();
        }



        private static void ThreadExceptionHandler(object sender, ThreadExceptionEventArgs e)
        {
            CrashManager.GenericExceptionHandler(e.Exception);
        }

        private static void ThreadHandler()
        {
        }

        private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
        {
            Exception exception1 = (Exception) args.ExceptionObject;
            CrashManager.GenericExceptionHandler(exception1);
        }






        private static bool _blnConsoleApp;
        private static bool _blnEmailIncludeScreenshot;
        private static bool _blnIgnoreDebugErrors;
        private static bool _blnKillAppOnException;
        private static bool _blnLogToEmail;
        //private static bool _blnLogToEmailOK;
        private static bool _blnLogToEventLog;
        private static bool _blnLogToEventLogOK;
        private static bool _blnLogToFile;
        private static bool _blnLogToFileOK;
        private static bool _blnLogToScreenshot;
        private static bool _blnLogToScreenshotOK;
        private static bool _blnLogToUI;
        private static Assembly _objParentAssembly;
        private static ImageFormat _ScreenshotImageFormat;
        private const string _strClassName = "CrashManager";
        private static string _strException;
        private static string _strExceptionType;
        private const string _strKeyError = "Error {0} retrieving key <{1}> from <appSettings> section of .config file";
        private const string _strKeyNotPresent = "The key <{0}> is not present in the <appSettings> section of .config file";
        private static string _strLogFullPath;
        private const string _strLogName = "UnhandledExceptionLog.txt";
        private static string _strScreenshotFullPath;
        private const string _strScreenshotName = "UnhandledException";
    }
}

